package Work;

import java.util.Objects;

/*****图书类*****/

public class Book {
    private String id;//图书号
    private String name;//书名
    private String author;//作者
    private double price;//价格
    private int amount;//剩余数量
 
    //计数与id分配变量
    private static int count=0;//书本计数
 
    //全参构造
    public Book(String id, String name, String author, double price, int amount) {
 
        this.id = id;
        this.name = name;
        this.author = author;
        if(price >= 0){
            this.price = price;
        }else{
            System.out.println("price不能小于0，请使用修改方法修改price!");
        }
        this.amount = amount;
 
        count++;//书本数量加一
    }
 
    public Book() {
        count++;//书本数量加一
    }
 
    //比较判断方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Book book = (Book) o;
        return name.equals(book.name);//返回书名
    }
 
    //未知
    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
 
    //toString
    @Override
    public String toString() {
        return "Book{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", amount=" + amount + 
                '}';
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getAuthor() {
        return author;
    }
 
    public void setAuthor(String author) {
        this.author = author;
    }
 
    public double getPrice() {
        return price;
    }
 
    public void setPrice(double price) {
        if(price >= 0){
            this.price = price;
        }else{
            System.out.println("price不能小于0，请重新使用使用修改方法修改price!");
        }
    }
 
    public int getAmount() {
        return amount;
    }
 
    public void setAmount(int amount) {
        this.amount = amount;
    }
 
    public String getId() {
        return id;
    }
 
    public void setId(String id) { this.id = id; }
 
    public static int getCount() { return count; }
 
    //书本数量只许清零
    public static void setCount() {  Book.count=0;}
}
